package com.wjf.shortlink.admin.common.convention.exception;

import com.wjf.shortlink.admin.common.convention.errorcode.BaseErrorCode;
import com.wjf.shortlink.admin.common.convention.result.Result;
import com.wjf.shortlink.admin.common.convention.result.Results;
import org.springframework.web.bind.MissingRequestValueException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    // 处理自定义异常
    @ExceptionHandler(ServiceException.class)
    public Result<Void> handlerGlobalException(ServiceException e) {
        return Results.failure(e);
    }

    // 处理接口入参缺失
    @ExceptionHandler(MissingRequestValueException.class)
    public Result<Void> handlerMissingRequestValueException(MissingRequestValueException e) {
        //System.out.print(e.getMessage());
        return Results.failure(BaseErrorCode.SERVICE_MISS_REQUEST_VALUE_ERROR.code(),
                BaseErrorCode.SERVICE_MISS_REQUEST_VALUE_ERROR.message());
    }
}
